<template>
  <div class="container">
    <van-nav-bar @click-left="clickLeft" left-arrow>
      <template #title>
        <van-dropdown-menu>
          <van-dropdown-item v-model="value1" :options="subject_List" />
        </van-dropdown-menu>
      </template>
    </van-nav-bar>
    <div class="phone-wrap">
      <van-tabs v-model="tabActive" swipeable>
        <van-tab title="章节练习">
          <Record :type="1" />
        </van-tab>
        <van-tab title="快速做题">
          <Record :type="2" />
        </van-tab>
        <van-tab title="模拟真题">
          <Record :type="3 " />
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import Record from "../components/Record";
export default {
  metaInfo: {
    title: "My Example App", // set a title
    meta: [
      {
        // set meta
        name: "keyWords",
        content: "My Example App"
      }
    ]
  },
  computed: {
    ...mapState({
      bank_id: state => state.question.bank_id,
      subject_id: state => state.question.subject_id,
      exerciseTab: state => state.question.exerciseTab,
      subject_List: state => {
        let arr = JSON.parse(state.question.subject_List);
        if (arr instanceof Array) {
          arr = arr.map(item => {
            item.text = item.subject_name;
            item.value = item.subject_id;
            return item;
          });
          return arr;
        }
      }
    })
  },
  components: {
    Record
  },
  data() {
    return {
      phoneBg: "#f3f3f3",
      dropList: [],
      showDrop: false,
      value1: 0,
      tabActive: 0
    };
  },
  created() {
    this.$nextTick(() => {
      this.tabActive = Number(this.exerciseTab);
      this.value1 = Number(this.subject_id);
    });
  },
  watch: {
    value1(val, old) {
      if (val != old) {
        this.$store.commit("subject_id", val);
      }
    },
    tabActive(val, old) {
      if (val != old) {
        this.$store.commit("exerciseTab", val);
        this.$store.commit("type", val + 1);
      }
    }
  },
  methods: {
    clickLeft() {
      this.$router.go(-1);
    }
  }
};
</script> 

<style lang="less" scoped>
@import "../question.less";
/deep/ .van-nav-bar {
  z-index: 99;
}

/deep/ .DropDown .van-popup--top {
  width: 200px;
}
.phone-wrap {
  background-color: #f3f3f3;
}
</style>
